package com.simon.seckill.controller;

import com.simon.seckill.Entities.Product;
import com.simon.seckill.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/page/")
public class PagesController {

    @Autowired
    ProductService productService;

    @RequestMapping("list")
    public String list(Map<String, Object> map) {
        List<Product> list = productService.getSeckillList();
        map.put("list", list);
        return "list";
    }

    @RequestMapping(value = "{id}/detail")
    public String detail(@PathVariable("id") Integer id, Map<String, Object> map) {
        Product product = productService.getProductById(id);
        map.put("product", product);
        return "detail";
    }
}
